<?php
/**
 * SimpleRbacRoleModel.php
 * Created by PhpStorm.
 * User: 江小波
 * Date: 2019/06/26
 * Time: 22:34
 */
namespace app\common\auto_curd\php_system\model;

use think\Db;

class SimpleRbacRoleModel
{
    /**
     * ID
     */
    protected $id = '';
    public function getId()
    {
        return $this->id;
    }
    public function setId($id)
    {
        $this->id = $id;
    }
    
    /**
     * 是否开启
     */
    protected $status = '1';
    public function getStatus()
    {
        return $this->status;
    }
    public function setStatus($status)
    {
        $this->status = $status;
    }
    
    /**
     * 创建时间
     */
    protected $create_ts = '0';
    public function getCreateTs()
    {
        return $this->create_ts;
    }
    public function setCreateTs($create_ts)
    {
        $this->create_ts = $create_ts;
    }
    
    /**
     * 修改时间
     */
    protected $update_ts = '0';
    public function getUpdateTs()
    {
        return $this->update_ts;
    }
    public function setUpdateTs($update_ts)
    {
        $this->update_ts = $update_ts;
    }
    
    /**
     * 平台ID
     */
    protected $platform_id = '0';
    public function getPlatformId()
    {
        return $this->platform_id;
    }
    public function setPlatformId($platform_id)
    {
        $this->platform_id = $platform_id;
    }
    
    /**
     * 角色名
     */
    protected $name = '';
    public function getName()
    {
        return $this->name;
    }
    public function setName($name)
    {
        $this->name = $name;
    }
    
    /**
     * 角色描述
     */
    protected $remark = '';
    public function getRemark()
    {
        return $this->remark;
    }
    public function setRemark($remark)
    {
        $this->remark = $remark;
    }
    
    /**
     * 权限节点(,1,2,3,)
     */
    protected $nodes = '';
    public function getNodes()
    {
        return $this->nodes;
    }
    public function setNodes($nodes)
    {
        $this->nodes = $nodes;
    }
    
    /**
     * constructor.
     * @param array $data
     */
    public function __construct($data=[])
    {

        // ID
        if(isset($data['id']))
        {
            $this->id = $data['id'];
        }

        // 是否开启
        if(isset($data['status']))
        {
            $this->status = $data['status'];
        }

        // 创建时间
        if(isset($data['create_ts']))
        {
            $this->create_ts = $data['create_ts'];
        }

        // 修改时间
        if(isset($data['update_ts']))
        {
            $this->update_ts = $data['update_ts'];
        }

        // 平台ID
        if(isset($data['platform_id']))
        {
            $this->platform_id = $data['platform_id'];
        }

        // 角色名
        if(isset($data['name']))
        {
            $this->name = $data['name'];
        }

        // 角色描述
        if(isset($data['remark']))
        {
            $this->remark = $data['remark'];
        }

        // 权限节点(,1,2,3,)
        if(isset($data['nodes']))
        {
            $this->nodes = $data['nodes'];
        }

    }
    
    /**
     * 获取分页信息
     * @param $where
     * @param array $extend
     * @return \think\Paginator
     */
    static public function paginate($where,$extend=[])
    {
        $handler = Db::table('simple_rbac_role');
        if(!empty($extend['field']))
        {
            $handler->field($extend['field']);
        }
        if(!empty($extend['order']))
        {
            $handler->order($extend['order']);
        }
        if(!empty($extend['group']))
        {
            $handler->group($extend['group']);
        }
        return $handler
            ->where($where)
            ->paginate();
    }
    
    /**
     * 添加|修改
     * @param $flag
     * @param $data
     * @param array $extend
     * @return int|string
     */
    static public function save($flag,$data,$extend=[])
    {
        if(empty($flag))
        {
            // 添加
            $data['create_ts'] = time();
            return Db::table('simple_rbac_role')
                ->insertGetId($data);
        }
        else
        {
            // 编辑
            $data['update_ts'] = time();
            return Db::table('simple_rbac_role')
                ->where('id',$flag)
                ->update($data);
        }
    }
    
    /**
     * 获取详情
     * @param $where
     * @param array $extend
     * @return array|false|null|\PDOStatement|string|\think\Model
     */
    static public function get($where,$extend=[])
    {
        $handler = Db::table('simple_rbac_role');
        if(!empty($extend['field']))
        {
            $handler->field($extend['field']);
        }
        if(!empty($extend['order']))
        {
            $handler->order($extend['order']);
        }
        if(!empty($extend['group']))
        {
            $handler->group($extend['group']);
        }
        return $handler
            ->where($where)
            ->find();
    }
    
    /**
     * 删除
     * @param $flag
     * @param array $extend
     * @return int
     */
    static public function delete($flag,$extend=[])
    {
        return Db::table('simple_rbac_role')
            ->where('id',$flag)
            ->delete();
    }
}